/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package business;

import dal.LocationsDAL;
import java.util.ArrayList;
import java.util.List;
import model.Locations;

/**
 *
 * @author Administrator
 */
public class LocationsBusiness {

    private LocationsDAL locationsDAL = new LocationsDAL();

    public boolean newLocation(Locations local) {
        if (locationsDAL.newLocation(local)) {
            return true;
        }
        return false;
    }

    public boolean updateLocation(Locations local) {
        if (locationsDAL.updateLocation(local)) {
            return true;
        }
        return false;
    }

    public int getRowInListAllLocation() {
        return locationsDAL.listAllLocation().size();
    }

    public List<Locations> listAllLocation(){
        return locationsDAL.listAllLocation();
    }

    public List<Locations> listLocationByPage(int pageID) {
        List<Locations> listAll = locationsDAL.listAllLocation();
        List<Locations> listLocalByPage = new ArrayList<Locations>();
        for (int i = (pageID - 1) * 4; i < (pageID * 4); i++) {
            try {
                listLocalByPage.add(listAll.get(i));
            } catch (IndexOutOfBoundsException e) {
                return listLocalByPage;
            }
        }
        return listLocalByPage;
    }
}
